package com.youchuang.action.user;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.youchuang.action.BaseAction;
import com.youchuang.bean.ReceiveAddress;
import com.youchuang.bean.User;
import com.youchuang.common.Constant;
import com.youchuang.service.UserService;

import net.sf.json.JSONArray;

/**
 * 用户查询地址信息
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/user")
@ParentPackage("shopping-default")
public class SelectAddressAction extends BaseAction {
	private Logger logger = Logger.getLogger(SelectAddressAction.class.getSimpleName());
	private List<ReceiveAddress> addressList;

	@Resource
	private UserService userService;

	@Action(value = "selectAddress", interceptorRefs = { @InterceptorRef(value = "loginStack") }, results = {
			@Result(name = ActionSupport.SUCCESS, location = "/WEB-INF/jsp/user/select_address_list.jsp") })
	public String execute() throws Exception {
		logger.info("exection is execute");

		User user = (User) session.get(Constant.S_USER);
		String userId = user.getId();

		addressList = userService.findReceiveAddressByUserId(userId);

		logger.info("response json = " + JSONArray.fromObject(addressList).toString());
		return Constant.SUCCESS;
	}

	public List<ReceiveAddress> getAddressList() {
		return addressList;
	}

	public void setAddressList(List<ReceiveAddress> addressList) {
		this.addressList = addressList;
	}

}
